package pos.data;

import java.io.FileNotFoundException;
import java.io.IOException;

import com.csvreader.CsvReader;

import pos.domain.Customer;

public class CSVCustomerDAO implements ICustomerDAO {

	private String fileName = "data/customers.csv"; 
	
	@Override
	public boolean authenticate(Customer c) {
	    boolean found = false;
    	CsvReader customers;
		try {
			customers = new CsvReader(fileName);
			customers.readHeaders();
			
			while (customers.readRecord() & !found){
				String currentcid = customers.get("login");
				String currentpass = customers.get("password");
				if(currentcid.equals(c.getLogin()) && currentpass.equals(c.getPassword())){
					found = true;
				}
                
			}
			customers.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    
		return found;
	}
	
}
